home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / compress / zipcmnt.zip / CMNTREAD.PAS < prev    next >
Pascal/Delphi Source File  |  1993-05-15  |  4KB  |  151 lines

  1. { Zip file comment reader 1.0                  }
  2. { Copyright (c) 1990 McBrine Computer Products }
  3. { See below for more info                      }
  4.  
  5. program commentread(zipfile,cmntfile,output);
  6. type                              { Comment is stored on the heap }
  7.  ptr=^foo;                        { Note TP4.0 will not accept 0..65535 }
  8.  foo=record                       { as a range for an array! }
  9.   bar:array[0..65534] of byte
  10.  end;
  11. var
  12.  zipfile,cmntfile:file of byte;
  13.  zipname,cmntname:string[80];
  14.  x,y,z:longint;
  15.  m,n,o,clength:word;
  16.  a,b,t:byte;
  17.  comment:ptr;
  18.  
  19. procedure sz;                     
  20.  begin                            { Too simple to be a procedure in its }
  21.   seek(zipfile,x)                 { own right, it seems; but it results in }
  22.  end;                             { a much shorter compiled program }
  23.  
  24. procedure rnp;
  25.  begin
  26.   read(zipfile,a,b)
  27.  end;
  28.  
  29. function rno:word;
  30.  begin
  31.   rnp;
  32.   rno:=a+256*b
  33.  end;
  34.  
  35. procedure gettype;
  36.  begin
  37.   x:=x+4;
  38.   t:=0;
  39.   rnp;
  40.   if (a=80) and (b=75) then
  41.    begin
  42.     rnp;
  43.     case a+b of
  44.       7:t:=1;
  45.       3:t:=2;
  46.      11:t:=3
  47.     end
  48.    end
  49.  end;
  50.  
  51. procedure error;
  52.  begin
  53.   writeln('I can''t read this ZIP file!');
  54.   halt
  55.  end;
  56.  
  57. procedure error1;
  58.  begin
  59.   writeln('Zip File Comment Reader 1.0');
  60.   writeln('by William J. McBrine III');
  61.   writeln('Copyright (c) 1990 McBrine Computer Products');
  62.   writeln;
  63.   writeln('Syntax is:');
  64.   writeln;
  65.   writeln('CMNTREAD zipfile[.zip] [cmntfile.ext]');
  66.   writeln;
  67.   writeln('"Zipfile" is the name of the file to read the comment from. The extension');
  68.   writeln('".ZIP" is assumed if none is given. "Cmntfile.ext" is the name of the file to');
  69.   writeln('write the comment to; "CON" (the screen) is used if no name is given.');
  70.   writeln;
  71.   writeln('This program is free software, distributed under the terms of the GNU General');
  72.   writeln('Public License as published by the Free Software Foundation, version 1. It is');
  73.   writeln('distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY. See');
  74.   writeln('LICENSE.DOC for details. It should have come with this program; if not, write:');
  75.   writeln;
  76.   writeln('Free Software Foundation, Inc. / 675 Massachusetts Avenue / Cambridge, MA 02139');
  77.   writeln;
  78.   writeln('author: William J. McBrine III / 514 S. Jackson St. / Salisbury, NC 28144-5428');
  79.   writeln('email : WILLIAM MCBRINE on HomeBoy''s Digital Undergound, (704) 637-2342  3-24');
  80.   writeln('                         & The Big Byte, (704) 279-2295  3-96 dual');
  81.   halt
  82.  end;
  83.  
  84. procedure skipfile;
  85.  begin
  86.   x:=x+14;
  87.   sz;
  88.   y:=rno;
  89.   z:=rno;
  90.   y:=y+65536*z;
  91.   x:=x+8;
  92.   sz;
  93.   m:=rno;
  94.   n:=rno;
  95.   x:=x+y+m+n+4;
  96.   sz
  97.  end;
  98.  
  99. procedure skipdir;
  100.  begin
  101.   x:=x+24;
  102.   sz;
  103.   m:=rno;
  104.   n:=rno;
  105.   o:=rno;
  106.   x:=x+m+n+o+18;
  107.   sz
  108.  end;
  109.  
  110. procedure writcmnt;
  111.  begin
  112.   writeln('Writing comment file: ',cmntname);
  113.   assign(cmntfile,cmntname);
  114.   rewrite(cmntfile);
  115.   if clength>0 then
  116.    with comment^ do for m:=0 to clength-1 do write(cmntfile,bar[m]);
  117.   close(cmntfile)
  118.  end;
  119.  
  120. begin
  121.  if (paramcount<>2) and (paramcount<>1) then error1;
  122.  zipname:=paramstr(1);
  123.  if paramcount=2 then cmntname:=paramstr(2)
  124.  else cmntname:='con';
  125.  if pos('.',zipname)=0 then zipname:=concat(zipname,'.zip');
  126.  writeln('Reading ZIP file: ',zipname);
  127.  assign(zipfile,zipname);
  128.  reset(zipfile);
  129.  x:=0;
  130.  repeat
  131.   gettype;
  132.   if t=0 then error;
  133.   case t of
  134.    1:skipfile;
  135.    2:skipdir
  136.   end
  137.  until t=3;
  138.  x:=x+16;
  139.  sz;
  140.  
  141. { All the above got us to the length of the zipcomment }
  142.  
  143.  clength:=rno;
  144.  mark(comment);
  145.  getmem(comment,clength);
  146.  if clength>0 then
  147.   with comment^ do for n:=0 to clength-1 do read(zipfile,bar[n]);
  148.  close(zipfile);
  149.  writcmnt
  150. end.
  151.